home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-09-02 | 5.7 KB | 177 lines | [TEXT/CCL2] |
- ;;; histogram-view.lisp
- ;;;
- ;;; Paul McCartney, Spring 1992
- ;;;
- ;;; Copyright © 1992 Paul McCartney. All Rights Reserved.
- ;;;
- ;;; Washington University Medical Informatics Training Program
- ;;;
- ;;; DESCRIPTION:
- ;;;
- ;;; This is a view which displays a histogram in 3D, with the vanishing
- ;;; point being the top-middle of the view.
- ;;;
- ;;; USE:
- ;;;
- ;;; histogram-view - view class for histogram view
- ;;; :x-start - horizontal start value
- ;;; :x-end - horizontal end value
- ;;; :y-start - vertical start value
- ;;; :y-end - vertical end value
- ;;; :n-bins - number of columns to display
- ;;; :bin-increment - size (range) of data values for each bin
- ;;; :bin-color - column color
- ;;; :bin-thickness - 3D thickness of each bin
- ;;; :value-fn - function to return the data value of an
- ;;; event given the event
- ;;;
- ;;; set-histogram-data - add a set of data points to the view
- ;;; set-histogram-range - set the view's horizontal and vertical range.
- ;;; histogram's vertical range is always anchored
- ;;; at 0
- ;;;
- ;;; HISTORY:
- ;;;
- ;;; 6/15/92 Created. - PM
- ;;;
-
- (in-package :ccl)
-
- (require :perspective-projection)
- (require :GWorld-view-extensions)
-
- (eval-when (:compile-toplevel :load-toplevel :execute)
- (export '(histogram-view set-histogram-data set-histogram-range)))
-
-
- (defstruct bin
- (start 0 :type fixnum)
- (end 0 :type fixnum)
- (size 0 :type fixnum))
-
-
- (defclass histogram-view (view)
- ((x-scale :initarg :x-scale :accessor x-scale)
- (y-scale :initarg :y-scale :accessor y-scale)
- (x-start :initarg :x-start :accessor x-start)
- (y-start :initarg :y-start :accessor y-start)
- (x-end :initarg :x-end :accessor x-end)
- (y-end :initarg :y-end :accessor y-end)
- (n-bins :initarg :n-bins :accessor n-bins)
- (bins :accessor bins)
- (bin-increment :initarg :bin-increment :accessor bin-increment)
- (bin-color :initarg :bin-color :accessor bin-color)
- (bin-thickness :initarg :bin-thickness :accessor bin-thickness)
- (perspective :initarg :perspective :accessor perspective)
- (value-fn :initarg :value-fn :accessor value-fn))
- (:default-initargs
- :x-start 0
- :x-end 10
- :y-start 0
- :y-end 10
- :x-scale 1
- :y-scale 1
- :n-bins 6
- :bin-increment 10
- :bin-color *green-color*
- :bin-thickness 7
- :perspective (make-perspective)
- :value-fn #'identity
- )
- )
-
-
- (defmethod initialize-instance ((view histogram-view) &rest initargs)
- (apply #'call-next-method view initargs)
- (make-histogram-bins view)
- (set-3D-origin view) )
-
-
- (defmethod view-draw-contents ((view histogram-view))
- (let* ((pos (view-scroll-position view))
- (size (view-size view))
- (top (point-v pos))
- (left (point-h pos))
- (bottom (+ top (point-v size)))
- (right (+ left (point-h size))))
- (with-GWorld-no-colorization (view left top right bottom)
- (dotimes (i (n-bins view))
- (let* ((bin (aref (bins view) i))
- (start (bin-start bin))
- (end (bin-end bin))
- (size (bin-size bin))
- (start-x (round (* start (x-scale view))))
- (end-x (round (* end (x-scale view))))
- (height (round (* size (y-scale view))))
- (bottom (point-v (view-size view))))
- (draw-block-below-horizon
- *GW-offscreen-view*
- (perspective view)
- (make-GW-point (+ (bin-thickness view) start-x) (- bottom height))
- (make-GW-point (- end-x (bin-thickness view)) bottom)
- (bin-color view)
- (bin-thickness view)) ))) ))
-
-
- (defmethod set-view-size ((view histogram-view) h &optional v)
- (call-next-method view h v)
- (set-histogram-range view (x-start view) (x-end view) (y-end view)) )
-
-
- (defmethod set-3D-origin ((view histogram-view))
- (setf (perspective-view-3D-origin (perspective view))
- (make-point (+ (point-h (view-scroll-position view))
- (round (point-h (view-size view)) 2))
- (point-v (view-scroll-position view)))))
-
-
- (defmethod make-histogram-bins ((view histogram-view))
- (setf (bins view) (make-array (list (n-bins view)) :element-type 'bin))
- (dotimes (i (n-bins view))
- (setf (aref (bins view) i)
- (make-bin
- :start (* i (bin-increment view))
- :end (1- (* (1+ i) (bin-increment view))) ))))
-
-
- (defmethod set-histogram-range ((view histogram-view) x-start x-end y-end)
- (let* ((old-x-scale (x-scale view))
- (old-y-scale (y-scale view))
- (x-scale (/ (point-h (view-size view)) (- x-end x-start)))
- (y-scale (/ (point-v (view-size view)) y-end))
- (scroll-position (view-scroll-position view))
- (x-scroll (round (* x-scale x-start))))
- (setf (x-start view) x-start)
- (setf (x-end view) x-end)
- (setf (y-end view) y-end)
- (setf (x-scale view) x-scale)
- (setf (y-scale view) y-scale)
-
- (when (or (/= x-scroll (point-h scroll-position))
- (/= x-scale old-x-scale)
- (/= y-scale old-y-scale))
- (setf (view-scroll-position view) (make-point x-scroll 0))
- (set-3D-origin view)
- (invalidate-view view)
- (set-view-scroll-position view x-scroll 0 t) ) ))
-
-
-
- ;;;;
- ;;;; EXTERNAL DATA I/O
- ;;;;
-
- (defmethod set-histogram-data ((view histogram-view) data-list)
- (dotimes (i (n-bins view))
- (let ((bin (aref (bins view) i)))
- (setf (bin-size bin) 0)))
- (dolist (data data-list)
- (dotimes (i (n-bins view))
- (let ((bin (aref (bins view) i))
- (value (funcall (value-fn view) data)))
- (if (<= (bin-start bin) value (bin-end bin))
- (incf (bin-size bin))) )))
- (invalidate-view view t) )
-
-
- (provide :histogram-view)